from PyQt4 import QtCore, QtGui

from limber.ui.dialogs.ui_showabilitydetails import Ui_ShowAbilityDetailsDialog
from limber.ui.dialogs import utils


class ShowAbilityDetailsDialog(QtGui.QDialog, Ui_ShowAbilityDetailsDialog):
    
    def __init__(self, parent=None, name='', value='', description=''):
        super(ShowAbilityDetailsDialog, self).__init__(parent)
        
        name_text = unicode(self.ability_name_label.text()) + name
        value_text = unicode(self.ability_value_label.text()) + unicode(value)
        
        self.ability_name_label.setText(name_text)
        self.ability_value_label.setText(value_text)
        self.description_browser.setText(description)
    
    @staticmethod
    def show_ability_details(parent=None, name='', value='', description='',
                             modal=True, return_instance=False):
        '''Shows a *ShowAbilityDetailsDialog* with the given infos.
        
        If *modal* is `True`(default), then the dialog is
        showed modally.
        
        If *return_instance* is `True`(default: `False`) then
        the dialog instance is returned.
        '''
        
        dlg = ShowAbilityDetailsDialog(parent, name, value, description)
        if modal:
            dlg.exec_()
        else:
            dlg.show()
        
        if return_instance:
            return dlg


utils.register_dialog(ShowAbilityDetailsDialog, 'show-ability-details')